<?php
error_reporting('IGNORE_REPEATED_ERRORS');
?>
<html>
<HEAD>

</HEAD>
<body>
<B>DRAFT REPORT</B><BR>
<?php

$charturl = "http://chart.apis.google.com/chart?cht=p3&chs=600x100&chd=t:";


mysql_connect("localhost", "root", "") or
    die("Could not connect: " . mysql_error());
mysql_select_db("QA");



$start_date = $_GET["start_date"];
$end_date = $_GET["end_date"];


if (strlen($start_date)<1) {
	$result = mysql_query("SELECT MIN(CALL_DATE) FROM QA.Caller");
	$row = mysql_fetch_array($result, MYSQL_BOTH);
	$start_date = $row[0];
}

if (strlen($end_date)<1) {
	$result = mysql_query("SELECT MAX(CALL_DATE) FROM QA.Caller");
	$row = mysql_fetch_array($result, MYSQL_BOTH);
	$end_date = $row[0];
}


$refer_descriptions = Array();
$qstring = "select QA.Refer.Reference_Number, QA.Refer.Refer_Description from QA.Refer";
$result = mysql_query($qstring);
while($row = mysql_fetch_array($result, MYSQL_BOTH)){
	$refer_descriptions[$row[0]] = $row[1];
}

echo "<BR>This report is for the date range ".$start_date." through ".$end_date." inclusively.<BR>";

$qstring = "select QA.Caller.Reference_Number, QA.211Feedback.Appropriate, QA.211Feedback.Refer, QA.211Feedback.Comments from QA.211Feedback, QA.Caller where QA.Caller.Reference_Number=QA.211Feedback.Caller_Reference AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" AND \"".$end_date."\" ORDER BY QA.211Feedback.Comments DESC";
//echo "Qstring: $qstring<BR>";
$result = mysql_query($qstring);
$appropriate = Array(0=>0,1=>0);
$refer = Array(1=>0,2=>0,3=>0);
echo "<TABLE border=1><TR><TD colspan=4>Feedback comments on 211 Service</TD></TR>";
echo "<TR><TD>Caller ID</TD><TD>Would Refer 211</TD><TD>Appropriate Referals</TD><TD>Comments</TD></TR>";
$total211feedback = 0;
while($row = mysql_fetch_array($result, MYSQL_BOTH)){
	echo "<TR";
	if ($row[1]==0 || $row[2]==2 || $row[2]==3){ echo " bgcolor=red ";}
	echo "><TD>$row[0]</TD><TD>";
	echo $refer_descriptions[$row[2]];
	echo "</TD><TD>";
	if($row[1]==1){echo "Yes";}
	if($row[1]==0){echo "No";}
	echo "</TD><TD>".$row[3]."</TD></TR>";
	$appropriate[$row[1]]++;
	$refer[$row[2]]++;
	$total211feedback++;
}
echo "<TR><TD colspan=4>END</TD></TR>";
echo "</TABLE><BR>";

$appropriatecharturl = $charturl;
$appropriatechartdata = "";
$appropriatechartlabels = "";
echo "<BR>Appropriate:<BR>";
foreach($appropriate as $key=>$value){
	$appropriatechartdata = $appropriatechartdata .",$value";
	if($key==1){$appropriatechartlabels = $appropriatechartlabels ."|". urlencode("Yes"." (".sprintf("%3.1f",($value/$total211feedback)*100)."%)");}
	if($key==0){$appropriatechartlabels = $appropriatechartlabels ."|". urlencode("No"." (".sprintf("%3.1f",($value/$total211feedback)*100)."%)");}
}
$appropriatecharturl = $appropriatecharturl.ltrim($appropriatechartdata,",")."&chl=".ltrim($appropriatechartlabels, "|");
echo "<img src=\"$appropriatecharturl\"><BR>";


$refer_descriptions = Array();
$qstring = "select QA.Refer.Reference_Number, QA.Refer.Refer_Description from QA.Refer";
$result = mysql_query($qstring);
while($row = mysql_fetch_array($result, MYSQL_BOTH)){
	$refer_descriptions[$row[0]] = $row[1];
}

$refercharturl = $charturl;
$referchartdata = "";
$referchartlabels = "";
echo "<BR>Refer:<BR>";
foreach($refer as $key=>$value){
	$referchartdata = $referchartdata .",$value";
	$referchartlabels = $referchartlabels ."|". urlencode($refer_descriptions[$key]." (".sprintf("%3.1f",($value/$total211feedback)*100)."%)");
}
$refercharturl = $refercharturl.ltrim($referchartdata,",")."&chl=".ltrim($referchartlabels, "|");
echo "<img src=\"$refercharturl\"><BR>";




?>







<br>
</body>
</html>
